import 'package:freezed_annotation/freezed_annotation.dart';
import 'dart:convert';

part 'navigation_response.freezed.dart';
part 'navigation_response.g.dart';

@freezed
class NavigationResponse with _$NavigationResponse {
  const factory NavigationResponse({
    @JsonKey(name: "c") required int c,
    @JsonKey(name: "m") required String m,
    @JsonKey(name: "d") required D d,
  }) = _NavigationResponse;

  factory NavigationResponse.fromJson(Map<String, dynamic> json) =>
      _$NavigationResponseFromJson(json);
}

@freezed
class D with _$D {
  const factory D({
    @JsonKey(name: "SY") required Sy sy,
    @JsonKey(name: "SYTJ") required Sy sytj,
  }) = _D;

  factory D.fromJson(Map<String, dynamic> json) => _$DFromJson(json);
}

@freezed
class Sy with _$Sy {
  const factory Sy({
    @JsonKey(name: "id") required String id,
    @JsonKey(name: "uniqid") required String uniqid,
    @JsonKey(name: "title") required String title,
    @JsonKey(name: "time") required String time,
    @JsonKey(name: "nav") required List<Nav> nav,
  }) = _Sy;

  factory Sy.fromJson(Map<String, dynamic> json) => _$SyFromJson(json);
}

@freezed
class Nav with _$Nav {
  const factory Nav({
    @JsonKey(name: "id") required String id,
    @JsonKey(name: "uniqid") required String uniqid,
    @JsonKey(name: "image") required String? image,
    @JsonKey(name: "title") required String title,
    @JsonKey(name: "time") required String time,
    @JsonKey(name: "attr") required Attr attr,
    @JsonKey(name: "target") required String target,
    @JsonKey(name: "pos") required String pos,
    @JsonKey(name: "top") String? top,
    @JsonKey(name: "slide") String? slide,
  }) = _Nav;

  factory Nav.fromJson(Map<String, dynamic> json) => _$NavFromJson(json);
}

enum Attr {
  @JsonValue("C")
  C,
  @JsonValue("S")
  S,
  @JsonValue("U")
  U
}

final attrValues = EnumValues({"C": Attr.C, "S": Attr.S, "U": Attr.U});

class EnumValues<T> {
  Map<String, T> map;
  late Map<T, String> reverseMap;

  EnumValues(this.map);

  Map<T, String> get reverse {
    reverseMap = map.map((k, v) => MapEntry(v, k));
    return reverseMap;
  }
}
